﻿<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
 
    <script type='text/html' template> 
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}"/>
    </script>   
    <div class='layui-form-item'>
        <label class='layui-form-label'>店铺名称<span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Name' value='{{ d.params.Name || '' }}' lay-verify='required' placeholder='店铺名称' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>   
    <!--<div class='layui-form-item'>
        <label class='layui-form-label'>店铺编码</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Code' value='{{ d.params.Code || '' }}' lay-verify='required' placeholder='店铺编码' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>-->   

    <div class='layui-form-item'>
        <label class='layui-form-label'>店铺Logo</label>
        <div class='layui-input-block'>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="selectImg">选择图片</button>
                <div class="layui-upload-list" id="divImgs"></div>
                <script type='text/html' template lay-done='layui.data.setUploads(d.params);'>
                    <input type="hidden" name="Logo" id="Logo" value="{{ d.params.Logo || '' }}">
                </script>
                <hr />
            </div>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>店铺简介</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Introduce' value='{{ d.params.Introduce || '' }}' lay-verify='' placeholder='店铺简介' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>   
    <div class='layui-form-item'>
        <label class='layui-form-label'>联系人<span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='UserName' value='{{ d.params.UserName || '' }}' lay-verify='required' placeholder='联系人' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>   
    <div class='layui-form-item'>
        <label class='layui-form-label'>联系电话<span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Phone' value='{{ d.params.Phone || '' }}' lay-verify='required' placeholder='联系电话' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>   
    <div class='layui-form-item'>
        <label class='layui-form-label'>所属县/区<span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"Area");'>
                <select name='Area' id='Area' lay-verify='required' lay-search>
                    <option value=""></option>
                </select>
            </script>
        </div>
    </div>   
    <div class='layui-form-item'>
        <label class='layui-form-label'>详细地址<span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Address' value='{{ d.params.Address || '' }}' lay-verify='required' placeholder='详细地址' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>   
    <div class='layui-form-item'>
        <label class='layui-form-label'>坐标<span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <button type="button" class="layui-btn layui-btn-normal" onclick="SelGps('{{ d.params.Gps || '' }}')">选择坐标</button>
                <span style="margin-left:12px;font-weight:bold" id="spangps">{{ d.params.Gps || '' }}</span>
                <input type='hidden' name='Gps' id="Gps" value='{{ d.params.Gps || '' }}'>
            </script>
        </div>
    </div>     
    <div class='layui-form-item'>
        <label class='layui-form-label'>状态 </label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <select name='State_Sel'>
                    <option value='0' {{ d.params.State_Sel == '0' ? 'selected' : '' }}>启用</option>
                    <option value='1' {{ d.params.State_Sel == '1' ? 'selected' : '' }}>停用</option>
                </select>
            </script> 
        </div>
    </div>
       
    <!--<div class='layui-form-item'>
        <label class='layui-form-label'>店铺二维码</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='QrCodePath' value='{{ d.params.QrCodePath || '' }}' lay-verify='required' placeholder='店铺二维码' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>-->   
    <div class='layui-form-item'>
        <label class='layui-form-label'>备注</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='RMK' value='{{ d.params.RMK || '' }}' lay-verify='' placeholder='备注' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div> 
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>
<style>
    .layui-upload-img {
        width: 100px;
        height: auto;
    }
</style>

<script type="text/javascript"> 
    var form, admin, $;
    layui.use(['form','admin','upload','laydate'], function () {
        form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        $ = layui.$;
        admin = layui.admin;
    });
    
    layui.data.getSelSource = function (d,sourceName) { 
         layui.use(['admin','form'], function () {
                $ = layui.$;
                form = layui.form;
                admin = layui.admin;

                if (sourceName == "Area") {
                    admin.req({
                        url: layui.setter.APIUrl + '/shop/StoreareaMgr/customerQuery', //实际使用请改成服务端真实接口
                        type: 'post',
                        done: function (res) {
                            layui.each(res.Data, function (index, eachdata) {
                                var strIsSel = '';
                                if (eachdata.Name == d.Area)
                                    strIsSel = "selected='selected'";
                                $("#Area").append("<option value='" + eachdata.Name + "' " + strIsSel + ">" + eachdata.Name + "</option>");
                            });
                            form.render('select');
                        }
                    });
                }
        });
    }
    
    layui.data.setUploads = function (d) {
        layui.use(['jquery', 'upload', 'admin'], function () {
            window.jQuery = window.$ = layui.jquery;
            upload = layui.upload,
            admin = layui.admin;
            //多图上传
            var uploadInst = upload.render({
                elem: '#selectImg'
              , url: '/WebAPI/file/uploadImgNew?access_token=' + layui.data('layuiAdmin').access_token
              , acceptMime: 'image/*'
              , multiple: false
              , done: function (res) {
                  if (res.ResultCode == 0) {
                      addImg(res.Data);
                      layer.msg('上传成功');
                  } else {
                      layer.msg(res.ResultInfo);
                  }
              }
            });
            var pics = d.Logo;
            if (pics != "" && pics != null && pics != 'null') {
                addImg({ name: pics, path: layui.setter.ImgPath + pics });
            }
        })
    }
    
    function addImg(src) {
        var div = "divimg3";
        var img = "Img3";
        var html = "    <div style=\"line-height:100px;float:left\" id='" + div + "'> " +
                           " <a style=\"float:right;line-height:10px;background-color:#ff0000;font-size:24px;color:white;border-top:3px solid #ff0000\" onclick=\"deletp3()\">×</a> " +
                           " <img id='" + img + "' src=\"" + src.path + "\"   alt=\"\" class=\"layui-upload-img\">" +
                       "</div>";
        $('#divImgs').html(html);
        $("#Logo").val(src.name);
    }
    //删除图片
    function deletp3() {
        $('#divImgs').html("");
        $("#Logo").val("");
    }

    //弹出一个iframe层
    function SelGps(gps) {
        layer.open({
            type: 2,
            title: '选择地址',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area: ['70%', '80%'],
            content: '/map.html?v=1&number=0&center=' + gps
        });
    };

    function SelGpsLoad(gps) {
        //alert(gps);
        $("#spangps").text(gps);
        $("#Gps").val(gps);
    }


</script>
